package me.shiqiang.im.service;

import me.shiqiang.im.vo.GroupUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author cuishiqiang
 * @date 2018/11/8 2:54 PM
 */
@Service
@CacheConfig(cacheNames = "groups")
public class GroupService {

    @Autowired
    GroupClient groupClient;


    @Cacheable(key = "'group.members'+#groupId")
    public List<Long> members(Long groupId) {
        return groupClient.getGroupUsers(groupId).res.stream().map( GroupUser::getUserId).collect(Collectors.toList());
    }

    @Cacheable(key = "'uid' + #userId  + 'session'+ #sessionId + 'ctype'+#ctype")
    public boolean isNoDisturb(Long userId, Long sessionId, int ctype){
        return groupClient.isNoDisturb(userId, sessionId, ctype);
    }


}
